package Controller;

import com.alibaba.fastjson.JSON;
import entity.Classify;
import entity.Return;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;


@WebServlet(name = "getClassify", value = "/getClassify")
public class classifyController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        super.doGet(request, response);
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        super.doPost(request, response);
        ArrayList<String> arrayList = new ArrayList<>();
        for (Classify classify:Classify.values()) {
            arrayList.add(String.valueOf(classify));
        }
        String allarrayList = JSON.toJSONString(arrayList);
        Return r = Return.ok().data("data", allarrayList);
        String returnStr = JSON.toJSONString(r);
        response.getWriter().println(returnStr);
        return;
    }
}
